package com.example.demo.SecurityConfig;

import com.example.demo.Data.User.User;
import org.springframework.security.core.GrantedAuthority;

public class UserGrantedAuthority implements GrantedAuthority
{
    private String authority;
    public UserGrantedAuthority(int authority)
    {
        setAuthority(authority);
    }
    @Override
    public String getAuthority()
    {
        return this.authority;
    }

    public UserGrantedAuthority setAuthority(int authority)
    {
        this.authority = authorityMapper(authority);
        return this;
    }

    private String authorityMapper(int authority)
    {
        switch (authority)
        {
            case User.ADMINISTRATOR: return "ADMINISTRATOR";
            case User.EXECUTIVE: return "EXECUTIVE";
            case User.FINANCIAL: return "FINANCIAL";
            case User.GENERAL: return "GENERAL";
            case User.STAFF: return "STAFF";
            case User.DEPARTMENT_MANAGER: return "DEPARTMENT_MANAGER";
            case User.VICE_GENERAL_MANAGER: return "VICE_GENERAL_MANAGER";
            case User.GENERAL_MANAGER: return "GENERAL_MANAGER";
            default: return null;
        }
    }
}
